home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#23 (Aug 87)
/
Dont panic source
/
DON'T PANIC main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-04-19
|
5KB
|
252 lines
/*
THIS PROGRAM WILL OPEN A NODE ON THE APPLE TALK NETWORK.
IT WILL THEN FIND ALL THE NODES OUT THERE. IF THE USR
ENTERS A MESSAGE IN THE EDIT FIELD AND PRESSES "SEND"
THE USR CAN ALSO OPEN A RECIEVING SOCKET FOR PACKETS SENT TO
IT.
FILE:
ATSIMPLE.C
BY:
TY SHIPMAN
DATE:
FEBRUARY 28, 1987
(C) Copyright 1987 Ty Shipman
All Rights Resereved.
This notice must appear in all copies. Commerical use of
this code forbidden, without prior written
permission of the author.
*/
#include "MacTypes.h"
#include "DialogMgr.h"
#include "EventMgr.h"
#include "ControlMgr.h"
#include "DON'T PANIC.h"
/*
THESE ARE ALL OF THE GLOBALS THAT ARE NEEDED TO RUN TO PROGRAM
*/
WindowPtr myWindow; /* points to the dialog window struct */
EventRecord myEvent; /*the event that just happened*/
Handle NodeName; /* a handle to the rsrc for the current name, usually set in Chooser */
main()
{
InitGraf(&thePort);
InitFonts();
FlushEvents( everyEvent, 0 );
InitWindows();
InitMenus();
TEInit();
InitDialogs(0L);
InitCursor();
MaxApplZone();
if( !Setup() )
while (DEvent()) ;
ExitToShell();
}
Setup()
{
if( PutUpWindow() ) /* go and get window and put it up with all if */
return(1);
return(0);
}
PutUpWindow()
{
/* this routine will put up the dialog specified and init all
buttons to default condition. It will also check to see if
the ports are configured for AppleTalk or not.
*/
ControlHandle itemHand;
int type;
Rect SelBox;
CouldDialog(DIALOG_ID); /*read into memory*/
myWindow = GetNewDialog(DIALOG_ID,NIL,(WindowPtr)-1);
NodeName = GetResource('STR ', -16096); /* the name of the unit set in chooser */
LoadResource(NodeName); /* this is the name of this station set in chooser */
SetPort(myWindow); /* hook in quickdraw */
GetDItem(myWindow,DISPLAYB,&type,&itemHand,&SelBox); /* THE DISPALY BUTTON, NO ITEMS IN LIST YET */
HiliteControl(itemHand,255); /*part 255, dim out*/
GetDItem(myWindow,SENDB,&type,&itemHand,&SelBox); /* I DON'T KNOW WHOM TO SEND TO YET */
HiliteControl(itemHand,255); /*part 255, dim out*/
WindUpdate(); /* do all the boxing necessary */
if( ATCheck() ) /* at this time get net stuff */
return(1);
ShowWindow(myWindow); /*all of a sudden up*/
return(0);
}
DEvent()
{
WindowPtr whichWindow;
int item;
DialogPtr theDialog;
SystemTask();
if (GetNextEvent(everyEvent, &myEvent))
{
switch (myEvent.what)
{
case driverEvt:
case networkEvt:
{
DoATNet(myEvent.message); /* pass handle to param block of type ????*/
break;
}
case mouseDown:
switch (FindWindow( myEvent.where, &whichWindow ))
{
case inGoAway:
if (TrackGoAway( myWindow, myEvent.where) )
{
CloseAT();
return(0);
}
break;
}
case updateEvt:
{
WindUpdate();
break;
}
default: ;
} /* end of case myEvent.what */
IsDialogEvent(&myEvent);
if( DialogSelect(&myEvent,&theDialog,&item) )
if( theDialog == myWindow) /* some DA's are Dialogs */
DoATDialog(item);
}
else
{
IsDialogEvent(&myEvent);
/* so the caret blinks */
DialogSelect(&myEvent,&theDialog,&item);
}
return(1);
}
DoATDialog(item)
int item; /*the item just hit*/
{
/* this routine will respond to the item hit on the dialog */
switch(item)
{
case LOOKB:
{
LookUp();
break;
}
case DISPLAYB:
{
Display();
break;
}
case SENDB:
{
Send();
break;
}
default:
break;
}/*end switch*/
}
WindUpdate()
{ /* this routine will draw all the necessary stuff in the window when an
update occures
*/
ControlHandle itemHand;
int type;
Rect SelBox;
GetDItem(myWindow,RECM,&type,&itemHand,&SelBox);
InsetRect(&SelBox,-1,-1);
FrameRect(&SelBox); /* THE RECIEVED MESSAGE BOX */
GetDItem(myWindow,MYNODE,&type,&itemHand,&SelBox);
SetIText(itemHand,(*NodeName)); /* the name set is chooser */
FrameRect(&SelBox); /* THE WHOM AM I FIELD */
GetDItem(myWindow,MYNUM,&type,&itemHand,&SelBox);
InsetRect(&SelBox,-2,-2);
FrameRect(&SelBox); /* THE WHOM AM I node number FIELD */
GetDItem(myWindow,SENDM,&type,&itemHand,&SelBox);
InsetRect(&SelBox,-2,-2);
FrameRect(&SelBox); /* THE WHOM AM I FIELD */
GetDItem(myWindow,NUMBER,&type,&itemHand,&SelBox);
InsetRect(&SelBox,-2,-2);
FrameRect(&SelBox); /* THE NUMBER OF NODES/SOCKETS FIELD */
GetDItem(myWindow,CNODEIS,&type,&itemHand,&SelBox);
InsetRect(&SelBox,-2,-2);
FrameRect(&SelBox); /* THE CURRENT NODE NUMBER FIELD */
GetDItem(myWindow,CNODENUM,&type,&itemHand,&SelBox);
InsetRect(&SelBox,-2,-2);
FrameRect(&SelBox); /* THE CURRENT NAME OF THE NUMBER FIELD */
}